/**
 * Created by Toma on 2016-6-17 12:40:34
 * nerve_h5
 */
(function () {
  'use strict';

  (function (size) {
    var docEl = document.documentElement,
        resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
        recalc = function () {
          docEl.style.fontSize = 20 * (docEl.clientWidth / size) + 'px';
        };
    window.addEventListener(resizeEvt, recalc, false);
    recalc();
  })(375);

  /**
   * 统计加载数
   */
  var pre = {
    files: 0,
    maxurl: 6,
    loading: document.querySelector('.loading'),
    change: function () {
      var _this = pre;
      _this.files++;
      _this.loading.innerHTML = _this.files + '%';
      if (_this.files >= _this.maxurl) {
        _this.done();
      }
    },
    done: function () {
      console.log('Toma is Ready (✿✪‿✪｡)ﾉ');
      this.loading.style.display = 'none';
    }
  };

  seajs.config({
    base: './',
    alias: {
      'seacss': 'lib/seajs-css.js',
      'seatext': 'lib/seajs-text.js',
      'zepto': 'lib/zepto.js',
      'swiper': 'lib/swiper.jquery.js',
      'animate': 'lib/swiper.animate.js',
      'data': 'js/data.js',
      'swipercss': 'lib/swiper.min.css',
      'style': 'css/style.css'
    },
    preload: ['seacss', 'seatext', 'zepto']
  });

  // js
  seajs.use('zepto', pre.change);
  seajs.use('swiper', function () {

    pre.change();
  });
  seajs.use('animate', pre.change);

  // 调用外部文件
  seajs.use('seatext', function () {
    seajs.use('data', pre.change);
  });

  // 加载样式
  seajs.use('seacss', function () {
    seajs.use('style', pre.change);
    seajs.use('swipercss', pre.change);
  });

  window.onload = function () {
    var swiper = new Swiper('.swiper-container', {
      direction: 'vertical'
    });
  };

})();